package me.send.data.service.provider;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import me.send.business.base.Pager;

public class WithdrawProvider {
    public String list_page(Map<String, Object> param) {
	String sql = "select withdrawOrderId,telephone,withdrawType,withdrawAccountNo,withdrawAmount,withdraw_order.createTime createTime,withdraw_order.status status,finishTime,authTime from withdraw_order,popuser where brokerId=popid ";
	if (param != null) {
	    String phone = (String) param.get("phone");
	    int status = (Integer) param.get("status");
	    double num = (Double) param.get("num");
	    String start=(String) param.get("start");
	    String end=(String) param.get("end");
	    Pager p = (Pager) param.get("page");
	    if (!phone.equals("")) {
		sql += " and telephone=" + phone;
	    }
	    if (status >= 0) {
		sql += " and withdraw_order.status=" + status;
	    }
	    if (num > 0) {
		sql += " and withdrawAmount>=" + num;
	    }
	    if(!start.equals("")){
		sql+=" and withdraw_order.createTime>='"+start+"'";
	    }
	    if(!end.equals("")){
		sql+=" and withdraw_order.createTime<'"+end+"'";
	    }
	    sql += " limit " + p.getStart() + "," + p.getRows();
	}
	return sql;
    }
    
    public String count_page(Map<String, Object> param) {
	String sql = "select count(*) from withdraw_order,popuser where brokerId=popid ";
	if (param != null) {
	    String phone = (String) param.get("phone");
	    int status = (Integer) param.get("status");
	    double num = (Double) param.get("num");
	    String start=(String) param.get("start");
	    String end=(String) param.get("end");
	    if (!phone.equals("")) {
		sql += " and telephone=" + phone;
	    }
	    if (status > 0) {
		sql += " and withdraw_order.status=" + status;
	    }
	    if (num > 0) {
		sql += " and withdraw_order.withdrawAmount>=" + num;
	    }
	    if(!start.equals("")){
		sql+=" and withdraw_order.createTime>='"+start+"'";
	    }
	    if(!end.equals("")){
		sql+=" and withdraw_order.createTime<'"+end+"'";
	    }
	}
	return sql;
    }
    
    public String allow(String brokerids){
	SimpleDateFormat adf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	String t=adf.format(new Date());
	String sql = "";
	if (brokerids != null) {
	    sql = "update withdraw_order set status=1,authTime='"+t+"' where withdrawOrderId in (" + brokerids
		  + ")";
	}
	return sql;
    }
}
